package com.hlw.hr_man.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.hlw.hr_man.dao.RoleDao;
import com.hlw.hr_man.util.JDBCUtil;

public class RoleDaoImpl implements RoleDao {

	@Override
	public int findRoleIdByRoleName(String rolename) {
		int roleid=0;
		Connection con=JDBCUtil.getConnection();
		StringBuffer sql=new StringBuffer("select role_id from hr_role where role_name=?");
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			pst.setString(1, rolename);
			ResultSet rs=pst.executeQuery();
			if(rs.next()){
				roleid=rs.getInt("role_id");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return roleid;
	}

	@Override
	public void addRoleByRoleName(String roleName) {
		// TODO Auto-generated method stub
		Connection con=JDBCUtil.getConnection();
		StringBuffer sql=new StringBuffer("insert into hr_role(role_name,role_funcs) values(?,?)");
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			pst.setString(1, roleName);
			pst.setString(2, "1,4,5,6,7,25,26,27,18,19,20,21,22,23,28,31,33");
			pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
